package com.gingkoo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.io.IOException;

/**
 * @author yoyo
 */
@SpringBootApplication
public class SpringBootDemo01Application {

    public static void main(String[] args) throws IOException, InterruptedException {
        // 指定jar包地址
        String jarPath = "/Users/yoyo/develop/java/project/SpringBoot/Gingkoo/金丘代码生成工具/gtools-beta.jar";
        // 执行指令
        ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "-Dfile.encoding=UTF-8", "-Xmx2048m", jarPath);
        // jar根目录
        processBuilder.directory(new File("/Users/yoyo/develop/java/project/SpringBoot/Gingkoo/金丘代码生成工具"));
        Process process = processBuilder.start();

        Thread.sleep(60000); // 等待60秒钟，让进程有时间启动

        if (process.isAlive()) {
            // 如果进程仍在运行，就终止它
            process.destroy();
            System.out.println("进程已被终止");
            // 终止主线程，停止项目
            System.out.println("Current JDK version: " + System.getProperty("java.version"));
            System.exit(0);
        }

        // 启动Spring Boot应用程序
        SpringApplication.run(SpringBootDemo01Application.class, args);

    }
}
